home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / amiga / stk_base.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  2KB  |  67 lines

  1.  
  2. /*
  3.  *  STK_BASE.C
  4.  *
  5.  *
  6.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  7.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  8.  *    DICE-LICENSE.TXT.
  9.  *
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/tasks.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. __near char *_stk_base = NULL;
  21. long _cur_fudge = 0;
  22. long _cur_chunk = 0;
  23.  
  24. extern long _stack_fudge;
  25. extern long _stack_chunk;
  26. extern long _ExitSP;
  27.  
  28. /*
  29.  *  Calculate base of stack and add fudge factor.  This code is brought
  30.  *  in if _stk_base is referenced, either by stack checking code or
  31.  *  by setjmp()/longjmp() code, which is why it isn't bundled with cstack.c
  32.  *
  33.  *  Under 1.3, there is no meaningful stack information, so we make a good
  34.  *  guess based on the stack pointer on program entry.
  35.  */
  36.  
  37. static __autoinit void
  38. cstack_init()
  39. {
  40.     struct Task *task = FindTask(NULL);
  41.     long fudge = _stack_fudge;
  42.     void dummy;
  43.  
  44.     if (&dummy < (void *)task->tc_SPLower || &dummy > (void *)task->tc_SPUpper) {
  45.     struct CommandLineInterface *cli = (void *)BADDR(((struct Process *)task)->pr_CLI);
  46.     _stk_base = (char *)(_ExitSP - (long)cli->cli_DefaultStack * 4 + fudge + 128);
  47.     } else {
  48.     _stk_base = (char *)task->tc_SPLower + fudge;
  49.     }
  50.     _cur_chunk = 0;
  51.     _cur_fudge = fudge;
  52. }
  53.  
  54. __stkargs void
  55. _stack_panic(str)
  56. const char *str;
  57. {
  58.     long fh;
  59.     if (fh = Output()) {
  60.     Write(fh, "stack_panic: ", 13);
  61.     Write(fh, str, strlen(str));
  62.     Write(fh, "\n", 1);
  63.     }
  64.     abort();
  65. }
  66.  
  67.